package com.unohacha.qqj.fzdr.personal.view.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.common.bean.HttpResult;
import com.unohacha.qqj.fzdr.common.http.RetrofitManager;
import com.unohacha.qqj.fzdr.util.Prefer;
import com.unohacha.qqj.mylibrary.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class FeedbackActivity extends BaseActivity {

    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;

    @BindView(R.id.et_feed_messages)
    EditText etFeedMessages;

    @OnClick(R.id.common_back)
    void onCommonBackClick() {
        finish();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_feedback;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setText("意见反馈");
        commonRightImage.setVisibility(View.INVISIBLE);
    }

    @OnClick(R.id.btn_commit_feedback)
    void onCommitFeedBackClick() {

        if (!etFeedMessages.getText().toString().equals("")) {
            Call<HttpResult<String>> call = RetrofitManager.getInstance().helpFeedback(
                    Prefer.getInstance().getToken(), "1", etFeedMessages.getText().toString().trim());
            call.enqueue(new Callback<HttpResult<String>>() {
                @Override
                public void onResponse(Call<HttpResult<String>> call, Response<HttpResult<String>> response) {
                    if (response.body() != null) {
                        Toast.makeText(getApplicationContext(), "感谢您宝贵的建议，客服会尽快给您回复", Toast.LENGTH_SHORT).show();
                        finish();
                    } else {
                        Toast.makeText(getApplicationContext(), "反馈失败", Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onFailure(Call<HttpResult<String>> call, Throwable t) {
                    Toast.makeText(getApplicationContext(), "反馈失败", Toast.LENGTH_SHORT).show();
                }
            });
        } else {
            Toast.makeText(getApplicationContext(), "反馈信息不能为空", Toast.LENGTH_SHORT).show();
        }

    }

}
